package top.jolyoulu.business.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import top.jolyoulu.business.web.dao.TestMapper;
import top.jolyoulu.business.web.entity.Test;
import top.jolyoulu.modules.mybatisplusmodule.plugin.page.JlPage;
import top.jolyoulu.webcommon.entity.ResultInfo;

import java.util.Random;
import java.util.UUID;

/**
 * @Author LuZhouJin
 * @Date 2023/5/4
 * mybatisplus-module 测试
 */
@RestController
@RequestMapping("/test/mybatis")
public class TestMybatisController {

    @Autowired
    private TestMapper testMapper;

    //测试新增
    @GetMapping("/insert")
    public ResultInfo<Boolean> mybatis() {
        String uuid = UUID.randomUUID().toString();
        Test test = new Test();
        test.setColumnOne(uuid);
        return ResultInfo.success(testMapper.insert(test) > 0);
    }

    //测试分页
    @GetMapping("/page")
    public ResultInfo<JlPage<Test>> mybatisPage() {
        return ResultInfo.success(JlPage.execute(1, 10, () -> testMapper.selectAll()));
    }

}
